package com.rd.student.jike.class4.wanghaixin.test0724;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class TestExecutor1 {
    private static final int CORE_POOL_SIZE = 5;
    private static final int MAX_POOL_SIZE = 20;
    private static final int QUEUE_CAPACITY = 2;
    private static final long KEEP_ALIVE_TIME = 1L;

    public static void main(String[] args) {
        ThreadPoolExecutor executor=new ThreadPoolExecutor(
                CORE_POOL_SIZE,
                MAX_POOL_SIZE,
                KEEP_ALIVE_TIME,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(QUEUE_CAPACITY),
                new ThreadPoolExecutor.DiscardPolicy());
        List<Future<String>> futureList = new ArrayList<>();
        MyCallable callable = new MyCallable();

        for (int i = 0; i < 12; i++) {
            Future<String> future = executor.submit(callable);
            futureList.add(future);
        }

        for (Future<String> future : futureList) {
            try {
                String s = future.get();
                System.out.println(s);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
}
